from selenium import webdriver

driver = webdriver.Chrome()

driver.get('http://cdn1.python3.vip/files/selenium/test4.html')
# 等待5s钟
driver.implicitly_wait(5)
# 点击按钮，跳出警示弹窗
driver.find_element_by_id('b1').click()
# 获取提示框的信息
print(driver.switch_to.alert.text)
# 点击提示框确认按钮
driver.switch_to.alert.accept()

'''
以下是确认弹窗
'''
driver.find_element_by_id('b2').click()
# 获取弹窗内容
print(driver.switch_to.alert.text)
# 点击确认
driver.switch_to.alert.accept()

driver.find_element_by_id('b2').click()
# 点击取消
driver.switch_to.alert.dismiss()

'''
以下是弹窗输入信息
'''

# 点击输入框按钮
driver.find_element_by_id('b3').click()

# 获取弹窗对象
alter = driver.switch_to.alert

# 获取弹窗内容
print(alter.text)

# 在弹窗内输入内容，点击确定
alter.send_keys('自动化测试selenium')
alter.accept()

# 取消弹窗
driver.find_element_by_id('b3').click()

alert = driver.switch_to.alert

alter.dismiss()

'''
以下是控制弹窗大小
'''

size_dict = driver.get_window_size()

print(size_dict['width'],size_dict['height'])

driver.set_window_size(1000,700)



'''
以下是当前网页信息
'''

print(driver.title)

print(driver.current_url)

print(driver.current_window_handle)

nwe_size = driver.get_window_size()

print(nwe_size['width'],nwe_size['height'])